<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<!-- 顶部包含 -->
	<%@ include file="/pages/common/common.jsp" %>

<div class= "container">
		 <div class="form-inline">
				模板：
				<select name="myselect" id="myselect" style="width:280px;height:30px;">
				    <option value="one">www.258zw.com</option>
				    <option value="two">www.xungue.cn</option>
				    <option value="three">www.xinshubao.net</option>
				    <option value="four">书香阁</option>
				    <option value="five">www.biqugexsw.com</option>
				    <option value="six">www.82xs.cc</option>
				    <option value="seven">www.cmxsw.com</option>
				    <option value="eight">www.suimengxiaoshuo.com</option>
				    <option value="nine">www.lingyu8.org</option>
				    <option value="ten">www.9tzw.com</option>
				    <option value="rizhao">https://www.rzlib.net/</option>
				    <option value="yanqing">情言中文网（https://www.yqzww.net）</option>
				    <option value="aixs">爱小说2txt（https://www.2txt.cc）</option>
				    <option value="zsb">追书帮（https://www.zhuishubang.com）</option>
				    <option value="two1">馨歌尔、爱尚小说、沸腾、(看书啦：https://www.kanshu.la)(爱尚小说http://www.23xs.me)</option>
				</select>
					
				<div class="input-group">
				    <input type="text" class="form-control" id="stopbookid" placeholder="书籍id" style="width:280px;">
				</div>
				<button type="submit" class="btn btn-primary" onclick="stopbook();">停止爬取</button>
					
				<div class="input-group">
				    <input type="text" class="form-control"  id="continuebookid" placeholder="书籍id" style="width:280px;">
				</div>
				<button type="submit" class="btn btn-primary" onclick="continuebook();">恢复爬取</button>
		  </div>
		  <hr>
		  <br />
		  
			  <span style="color:red;">网址根目录*</span>
			  <div class="form-group">
			    <input type="text" class="form-control" name="baseurl" id="baseurl" placeholder="网址根目录"  >
			  </div>
			  
			   <span style="color:red;">书籍网址*</span>
			  <div class="form-group">
			    <input type="text" class="form-control" name="bookurl" id="bookurl" placeholder="书籍网址" >
			  </div>
			  <span style="color:red;">书名*</span>
			   <div class="form-group">
			    <input type="text" class="form-control" name="booknameelement" id="booknameelement"   placeholder="书名" >
			  </div>
			   
			  <span style="color:red;">作者*</span>
			  <div class="form-group">
			    <input type="text" class="form-control" name="authorelement"  id="authorelement"  placeholder="作者" >
			  </div>
		  
		   <span style="color:red;">前置最新章节数*</span>
			  <div class="form-group">
			    <input type="text" class="form-control" name="presection" id="presection"   placeholder="前置最新章节数" >
			  </div>
			  
			   <span style="color:red;">连载状态0,1*</span>
			    <div class="form-group">
			   <input type="text" class="form-control" name="overstateelement" id="overstateelement"   placeholder="连载状态0,1" >
			  </div>
		  
			  <span style="color:red;">内容替换字符串*</span>
			   <div class="form-group"> 
			    <input type="text" class="form-control" name="replacestr" id="replacestr"   placeholder="章节内容替换字符串，多个以英文逗号隔开" >
			  </div>
			  <span style="color:red;">是否有多页true,false*</span>
			<div class="form-group"> 
			    <input type="text" class="form-control" name="multipage" id="multipage"   placeholder="是否有多页true,false" >
			</div>
			   下一页拼接规则
		  <div class="form-group"> 
		   <input type="text" class="form-control" name="nextpage" id="nextpage"   placeholder="下一页拼接规则" >
		  </div>
		 
		  章节页数 
		  <div class="form-group"> 
		   <input type="text" class="form-control" name="pagenum" id="pagenum"   placeholder="章节页数" >
		  </div>
		  <span style="color:red;">封面获取*</span>
		  <div class="form-group">
		    <input type="text" class="form-control" name="coverimgelement" id="coverimgelement"   placeholder="封面获取方式CSS选择器" >
		  </div>
		  
		  
		  <span style="color:red;">简介获取方式*</span>
		  <div class="form-group"> 
		    <input type="text" class="form-control" name="introduceelement" id="introduceelement"   placeholder="简介获取方式CSS选择器" >
		    </div>
		  <span style="color:red;">章节链接获取方式CSS选择器*</span>
		  <div class="form-group">
		    <input type="text" class="form-control" name="sectionelement" id="sectionelement"   placeholder="章节链接获取方式CSS选择器" >
		  </div>
		  <span style="color:red;">章节内容获取方式CSS选择器*</span>
		  <div class="form-group">
		    <input type="text" class="form-control" name="contentelement" id="contentelement"   placeholder="章节内容获取方式CSS选择器" >
		  </div>
		  <span style="color:red;">章节名称CSS选择器*</span>
		  <div class="form-group"> 
		    <input type="text" class="form-control" name="secnameelement" id="secnameelement"   placeholder="章节名称CSS选择器" >
		  </div>
		 <br />
		  <div class="form-group" style="text-align:center">
		    <input type="submit" class="btn btn-default" id="submit" value="提交">
		    <input type="submit" class="btn btn-default" id="test" value="测试">
		    <input type="submit" class="btn btn-default" id="polling" value="轮询测试">
		  </div>
		  <div class="form-group">
		   <p id="name"></p>
		   <p id="author"></p> 	
		   <p id="serialize"></p>
		   <p id="cover"></p>
		   <p id="intro"></p>
		   <p id="secnum"></p>
		   <p id="sectioncontent"></p>
		  </div>
	</div>
	<script type="text/javascript">
	$(function(){
		
		$("#myselect").change(function(){
		    var opt=$("#myselect").val();
		    if(opt == "one"){
		    	$("#sectionelement").val("ul[id=chapterlist] li");
		    	$("#contentelement").val("div[id=chapterContent]");
		    	$("#coverimgelement").val("div[class=content] div[class=img]");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=book_content_text] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("https://www.258zw.com");
		    }
		    if(opt == "two"){
		    	$("#sectionelement").val("div[id=list] dl dd");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg] img");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("9");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("https://www.xungue.cn");
		    }
		    if(opt == "three"){
		    	$("#sectionelement").val("div[id=list] ul[class=_chapter] li");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg] img");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("true");
		    	//$("#baseurl").val("http://www.xinshubao.net");
		    }
		    if(opt == "four"){
		    	$("#sectionelement").val("ul[class=mulu_list] li");
		    	$("#contentelement").val("div[id=htmlContent]");
		    	$("#coverimgelement").val("div[class=pic] a[class=img] img");
		    	$("#introduceelement").val("div[class=book] div[class=js]");
		    	$("#secnameelement").val("td[class=ydleft] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("http://www.f96.net");
		    }
		    if(opt == "five"){
		    	$("#sectionelement").val("div[class=listmain] dl dd");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[class=cover] img");
		    	$("#introduceelement").val("div[class=intro]");
		    	$("#secnameelement").val("div[class=content] h1");
		    	$("#presection").val("9");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("https://www.biqugexsw.com");
		    }
		    if(opt == "six"){
		    	$("#sectionelement").val("div[id=list-chapterAll] dd");
		    	$("#contentelement").val("div[class=readcontent]");
		    	$("#coverimgelement").val("div[class=bookcover] img");
		    	$("#introduceelement").val("p[class=bookintro]");
		    	$("#secnameelement").val("div[class=book] h1[class=pt10]");
		    	$("#presection").val("9");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("https://www.biqugexsw.com");
		    }
		    if(opt == "seven"){
		    	$("#sectionelement").val("ul[id=chapterlist] li");
		    	$("#contentelement").val("div[id=book_text]");
		    	$("#coverimgelement").val("div[class=content] div[class=img]");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=book_content_text] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//$("#baseurl").val("https://www.cmxsw.com");
		    }
		    if(opt == "eight"){
		    	$("#sectionelement").val("div[class=mulu] ul li");
		    	$("#contentelement").val("div[class=novel] p");
		    	$("#coverimgelement").val("div[class=jieshao] div[class=lf] img");
		    	$("#introduceelement").val("div[class=rt] div[class=intro]");
		    	$("#secnameelement").val("div[class=novel] h1");
		    	$("#presection").val("9");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    }
		    if(opt == "nine"){
		    	$("#sectionelement").val("div[class=ml_list] ul li");
		    	$("#contentelement").val("p[class=articlecontent]");
		    	$("#coverimgelement").val("img[alt=守夜人]");
		    	$("#introduceelement").val("div[class=introduce] p[class=jj]");
		    	$("#secnameelement").val("div[class=nr_title] h3");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    }
		    if(opt == "ten"){
		    	$("#sectionelement").val("div[id=list]  ul li");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg] img");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    }
		    if(opt == "rizhao"){
		    	$("#sectionelement").val("div[class=ListChapter] ul li");
		    	$("#contentelement").val("div[class=book_img] img");
		    	$("#coverimgelement").val("div[id=fmimg] img");
		    	$("#introduceelement").val("div[class=book_intro]");
		    	$("#secnameelement").val("div[id=chapter_title]");
		    	$("#presection").val("12");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    }
		    if(opt == "yanqing"){
		    	$("#sectionelement").val("div[class=article-list] dl dd");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg]  img");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
		    	//情言中文网（https://www.yqzww.net）

		    }
		    if(opt == "aixs"){
		    	$("#sectionelement").val("div[id=list] dl dd");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg]  img");
		    	$("#introduceelement").val("div[id=sidebar] div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("8");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
			    //爱小说2txt（https://www.2txt.cc）
		
		    }
		    if(opt == "zsb"){
		    	$("#sectionelement").val("div[class=chapterList] div[class=chapterCon] ul li");
		    	$("#contentelement").val("div[class=articleCon] p");
		    	$("#coverimgelement").val("div[class=bookImg] img");
		    	$("#introduceelement").val("div[class=introCon] p");
		    	$("#secnameelement").val("div[class=articleTitle] h2");
		    	$("#presection").val("0");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
			    //追书帮https://www.zhuishubang.com
		    }
		    if(opt == "two1"){
		    	$("#sectionelement").val("div[id=list] dl dd");
		    	$("#contentelement").val("div[id=content]");
		    	$("#coverimgelement").val("div[id=fmimg]");
		    	$("#introduceelement").val("div[id=intro]");
		    	$("#secnameelement").val("div[class=bookname] h1");
		    	$("#presection").val("12");
		    	$("#nextpage").val("_");
		    	$("#pagenum").val("3");
		    	$("#multipage").val("false");
			    //追书帮https://www.zhuishubang.com
		    }
		    
		});
		
		$("#submit").on("click", function(){
			var param = getparam();
			param.method="single";
			$.ajax({
				url:"${ctx }/crawler",
				method:"POST",
				data:param,
				dataType:"json",
				success:function(data){
					alert(data.resultdesc);
				},
			})
		});
		$("#test").on("click", function(){
			var param = getparam();
			param.method="singletest";
			$.ajax({
				url:"${ctx }/crawler",
				method:"POST",
				data:param,
				dataType:"json",
				success:function(data){
					
					if(data.success){
						$("#name").html("书名："+data.object.book.name);
						$("#author").html("作者："+data.object.book.author);
						$("#serialize").html("是否连载中："+data.object.book.serialize);
						$("#cover").html("封面："+data.object.book.cover);
						$("#intro").html("简介："+data.object.book.intro);
						$("#secnum").html("章节数量："+data.object.sectionnum);
						$("#sectioncontent").html("章节内容：<br>"+data.object.section);
					}
					alert(data.resultdesc);
				},
			})
		});
		
		$("#polling").on("click", function(){
			var values = [];
			$('#myselect option').each(function(i) {
				values[i] = $(this).val();
		    }); 
			var flag = true;
			var resultdesc = "";
			for(var i=0; i<values.length;i++){
				if(flag){
					$("#myselect").val(values[i]);
					$("#myselect").change();
					var param = getparam();
					param.method="singletest";
					$.ajax({
						url:"${ctx }/crawler",
						method:"POST",
						data:param,
						dataType:"json",
						async:false,
						success:function(data){
							console.log(JSON.stringify(data));
							$("#name").html("循环测试中，当前执行第"+i+"此测试");
							if(data.success){
								$("#name").html("书名："+data.object.book.name);
								$("#author").html("作者："+data.object.book.author);
								$("#serialize").html("是否连载中："+data.object.book.serialize);
								$("#cover").html("封面："+data.object.book.cover);
								$("#intro").html("简介："+data.object.book.intro);
								$("#secnum").html("章节数量："+data.object.sectionnum);
								$("#sectioncontent").html("章节内容：<br>"+data.object.section);
								flag = false;
								resultdesc = data.resultdesc;
								console.log("hhhhhhhhhhhhhhhhhhhhhhhhhhhh"+resultdesc);
							}
						},
					}) 
					var start = (new Date()).getTime();
				    while((new Date()).getTime() - start < 2000) {
				        continue;
				    }
				}else{
					alert(resultdesc)
					break;
				}
			}
		});
	})
	function getparam(){
		var param = new Object();
		param.bookurl=$("#bookurl").val();
		param.baseurl = $("#baseurl").val();
		param.sectionelement = $("#sectionelement").val();
		param.contentelement = $("#contentelement").val();
		param.booknameelement = $("#booknameelement").val();
		param.presection = $("#presection").val();
		param.authorelement = $("#authorelement").val();
		param.coverimgelement = $("#coverimgelement").val();
		param.overstateelement = $("#overstateelement").val();
		param.introduceelement = $("#introduceelement").val();
		param.secnameelement = $("#secnameelement").val();
		param.replacestr = $("#replacestr").val();
		param.multipage = $("#multipage").val();
		param.nextpage = $("#nextpage").val();
		param.pagenum = $("#pagenum").val();
		return param;
	}
	
	function stopbook(){
		$.ajax({
			url:"${ctx }/crawler",
			method:"POST",
			data:{bookid:$("#stopbookid").val(),method:"stopbook"},
			dataType:"json",
			success:function(data){
				alert(data.desc);
			},
		})
	}
	function continuebook(){
		$.ajax({
			url:"${ctx }/crawler",
			method:"POST",
			data:{bookid:$("#continuebookid").val(),method:"continue"},
			dataType:"json",
			success:function(data){
				alert(data.desc);
			},
		})
	}
	</script>
</body>
</html>